package com.auction.controller;

import com.auction.common.core.controller.MyBaseController;

import com.auction.common.utils.ReturnResult;
import com.auction.entity.ProductClassify;
import com.auction.service.ProductClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
@Api(tags = "分类")
public class ProductClassifyController extends MyBaseController {
    @Autowired
    ProductClassifyService productClassifyService;


    @ApiOperation("添加分类商品")
    @PostMapping("/savesify")
    public ReturnResult savesify(@RequestBody ProductClassify productClassify){
        int re=productClassifyService.saveEntity(productClassify);
            return saveResult(re) ;
    }

    @ApiOperation(value = "修改分类图片", notes = "根据分类ID修改图片信息")
    @PutMapping("/classify/updateImage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "分类ID", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "image", value = "图片URL", required = true, dataType = "String", paramType = "query")
    })
    public ReturnResult updateImage(@RequestBody Map<String,Object> map) {
        int re = productClassifyService.updateClassifyImage((Integer) map.get("id"), (String) map.get("image"));
        return updateResult(re);
    }


    @ApiOperation("设置为推荐分类")
    @PutMapping("/classify/updateFeatured")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "分类ID", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "featured", value = "推荐标志，1代表推荐，0代表不推荐", required = true, dataType = "Integer", paramType = "query")
    })
    public ReturnResult updateFeatured(@RequestBody Map<String,Integer> map) {
        int re = productClassifyService.updateClassifyStatus(map.get("id"),map.get("featured"));
        return updateResult(re);
    }

    @ApiOperation("分类查询商品")
    @GetMapping("/querysify")
    public ReturnResult querysify(){
        List<Map> result = productClassifyService.querysify();
        return success("商品列表", result);
    }

    @ApiOperation("删除分类")
    @DeleteMapping("/classify/delete")
    public ReturnResult deleteClassify(@RequestParam("id") Integer id) {
        int res = productClassifyService.deleteEntity(id);
        return deleteResult(res);
    }

}
